package com.emr.web.controller.emr;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Deahtdis;
import com.emr.module.domain.Guanchajl;
import com.emr.module.service.IGuanchajlService;
import com.emr.module.service.IPersonalService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 观察记录 信息操作处理
 * 
 * @author emr
 * @date 2019-02-21
 */
@Controller
@RequestMapping("/module/guanchajl")
public class GuanchajlController extends BaseController
{
    private String prefix = "module/guanchajl";
	
	@Autowired
	private IGuanchajlService guanchajlService;
	@Autowired
	private IPersonalService ipersonalService ;
	@RequiresPermissions("module:guanchajl:view")
	@GetMapping()
	public String guanchajl()
	{
	    return prefix + "/guanchajl";
	}
	
	/**
	 * 查询观察记录列表
	 */
	@RequiresPermissions("module:guanchajl:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Guanchajl guanchajl)
	{
		startPage();
		if("".equals(guanchajl.getPatientName())){
			guanchajl.setPatientName(null);
		}
        List<Guanchajl> list = guanchajlService.selectGuanchajlList(guanchajl);
		return getDataTable(list);
	}
	
	/**
	 * 新增观察记录
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("posts",ipersonalService.selectIcdAll());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存观察记录
	 */
	@RequiresPermissions("module:guanchajl:add")
	@Log(title = "观察记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Guanchajl guanchajl)
	{		
		return toAjax(guanchajlService.insertGuanchajl(guanchajl));
	}

	/**
	 * 修改观察记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Guanchajl guanchajl = guanchajlService.selectGuanchajlById(id);
		mmap.put("posts", ipersonalService.selectUPersonalByIds(guanchajl.getBingrenId()));
		mmap.put("guanchajl", guanchajl);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存观察记录
	 */
	@RequiresPermissions("module:guanchajl:edit")
	@Log(title = "观察记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Guanchajl guanchajl)
	{		
		return toAjax(guanchajlService.updateGuanchajl(guanchajl));
	}
	
	/**
	 * 删除观察记录
	 */
	@RequiresPermissions("module:guanchajl:remove")
	@Log(title = "观察记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(guanchajlService.deleteGuanchajlByIds(ids));
	}
	
}
